package com.rdxer.service;

import com.rdxer.repository.AccountRepository;
import com.rdxer.core.ex.ListEx;
import com.rdxer.core.utils.EncryptionUtils;
import com.rdxer.model.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class InitialService {
    @Autowired
    AccountRepository accountRepository;
    @Autowired
    AccountService accountService;

    @Autowired
    PasswordEncoder passwordEncoder;


    public void check() {
        if (accountRepository.count() > 0) {
            throw new RuntimeException("404 被拒绝访问");
//            accountRepository.deleteAll();
        }
    }


    public void setUpDeptRoleInfo() {
        // 填充角色表

    }

    // 创建管理员
    public void addSuperAdmin(String username, String password, String displayName) {
        Account account = Account.builder()
                .password(password)
                .username(username)
                .displayName(displayName)
                .roles(Account.Role.admin.name())
                .entryDate(System.currentTimeMillis())
                .build();
        accountService.register(account);
    }
}
